package com.harboursoftware.xstorage.model;

import java.io.Serializable;

import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * TODO:是否需要 displayName这个属性 User model.
 * 表示一个X-Storage的用户。
 * 
 * @author Simon Leung
 * @since 0.1
 */
public class XUser implements Serializable {
    private static final long serialVersionUID = 5576299604639956248L;
    private String id;
    private String accessKeyId;
    private String secretAccessKey;
    private String email;
    private String displayName;
    
    public XUser(){}
    
    public XUser(String id, String displayName) {
        this(id, null, null, null, displayName);
    }

    public XUser(String id, String accessKeyId, String secretAccessKey, String email, String displayName) {
        this.id = id;
        this.accessKeyId = accessKeyId;
        this.secretAccessKey = secretAccessKey;
        this.email = email;
        this.displayName = displayName;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getAccessKeyId() {
        return accessKeyId;
    }

    public void setAccessKeyId(String accessKeyId) {
        this.accessKeyId = accessKeyId;
    }

    public String getSecretAccessKey() {
        return secretAccessKey;
    }

    public void setSecretAccessKey(String secretAccessKey) {
        this.secretAccessKey = secretAccessKey;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getDisplayName() {
        return displayName;
    }

    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        return result;
    }

    
    
    /**
     * 仅通过XUser.id判断用户是否相等。
     * @param obj
     * @return 如果两者id相等返回true，否则返回false
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        XUser other = (XUser) obj;
        if (id == null) {
            if (other.id != null)
                return false;
        } else if (!id.equals(other.id))
            return false;
        return true;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}
